{include file="public_iframe:head"}

<div class="wrapper wrapper-content animated fadeInRight">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>角色名称 - 角色编辑</h5>
			<div class="ibox-tools" style="margin-top: -9px;">
				<button onclick="history.go(-1);" class="btn btn-primary"><i class="fa fa-arrow-left"></i> 返回</button>
			</div>
		</div>
		<div class="ibox-content">
			<form action="{:url('Admin/Admin/roleSave')}" method="post" enctype="multipart/form-data" id="roleform" class="form-horizontal">
				{if condition="isset($detail['role_id'])"}
					<input type="hidden" name="role_id" value="{$detail.role_id}">
				{/if}
				<div class="form-group">
					<label class="col-sm-2 control-label">角色名称</label>

					<div class="col-sm-6">
						<input type="text" class="form-control" name="data[role_name]" id="role_name" {if condition="isset($detail['role_name'])"} value="{$detail.role_name}"{/if}>
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">角色描述</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" id="role_desc" name="data[role_desc]" value="{if condition="isset($detail['role_desc'])"}{$detail.role_desc}{/if}">
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">权限分配</label>

					<div class="col-sm-6">
						<table data-toggle="table" class="table table-hover"
						>
							<thead>
								<th class="col-sm-3"><input id="cls_full" onclick="choosebox(this)" type="checkbox">
								<label>全选</label></th>
								<th></th>
							</thead>
							<tbody>
							{foreach name="modules" item="menu" key="kk"}
								<tr>
									<td>
										<label>{$group[$kk]}</label>
										<input value="1" cka="mod-{$kk}" type="checkbox">
										<label>全部</label>
									</td>
									<td>
										{foreach name="menu" item="vv"}
											<label class="checkbox-inline">
												<input class="checkbox" name="right[]"  {if condition="isset($vv.enable) && $vv.enable eq 1"}checked{/if}  value="{$vv.id}" ck="mod-{$kk}" type="checkbox">{$vv.name}
											</label>
										{/foreach}
									</td>
								</tr>
							{/foreach}
							</tbody>
						</table>
					</div>
				</div>
				<div class="hr-line-dashed"></div>
				<div class="form-group">
					<div class="col-sm-4 col-sm-offset-2">
						<!--<button class="btn btn-primary" type="submit">提交</button>-->
						<!--href="JavaScript:void(0);" onclick="roleSubmit();"-->
						<a href="JavaScript:void(0);" onclick="roleSubmit();" class="btn btn-primary" id="submitBtn">确认提交</a>
					</div>
				</div>
			</form>
		</div>
	</div>
	<!-- End Panel Basic -->
</div>
<script src="__STATIC__/admin/js/jquery.min.js?v=2.1.4"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$(":checkbox[cka]").click(function(){
			var $cks = $(":checkbox[ck='"+$(this).attr("cka")+"']");
			if($(this).is(':checked')){
				$cks.each(function(){$(this).prop("checked",true);});
			}else{
				$cks.each(function(){$(this).removeAttr('checked');});
			}
		});
	});

	function choosebox(o){
		var vt = $(o).is(':checked');
		if(vt){
			$('input[type=checkbox]').prop('checked',vt);
		}else{
			$('input[type=checkbox]').removeAttr('checked');
		}
	}

	function roleSubmit(){
		if($('#role_name').val() == '' ){
			layer.alert('角色名称不能为空', {icon: 2});
			return false;
		}
		$('#roleform').submit();
	}
</script>
</body>
</html>